package com.pn.controller;

import com.pn.entity.Purchase;
import com.pn.entity.Store;
import com.pn.service.ProductService;
import com.pn.service.PurchaseService;
import com.pn.service.StoreService;
import com.pn.utils.PageBean;
import com.pn.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;
    @Autowired
    private StoreService storeService;

    //添加采购单
    @PostMapping("/purchase-add")
    public Result purchaseAdd(@RequestBody Purchase purchase){
        Result result = purchaseService.insertPurchase(purchase);
        return result;
    }
    //查询所有仓库
    @GetMapping("/store-list")
    public Result storeList(){
        List<Store> stores = storeService.storeList();
        return Result.ok(stores);
    }

    //显示采购列表
    @GetMapping("/purchase-page-list")
    public Result<PageBean<Purchase>> purchasePageList(Purchase purchase){
       PageBean pageBean =  purchaseService.purchasePageList(purchase);
       return Result.ok(pageBean);
    }

    //删除采购单
    @DeleteMapping("/purchase-delete/{buyId}")
    public Result purchaseDelete(@PathVariable Integer buyId){
        Result result = purchaseService.purchaseDeleteByid(buyId);
        return result;
    }

    //修改采购单
    @PutMapping("/purchase-update")
    public Result purchaseUpdate(@RequestBody Purchase purchase){
        Result result = purchaseService.purchaseUpdate(purchase);
        return result;
    }

    //采购单生成入库单
    @PostMapping("/in-warehouse-record-add")
    public Result inWarehouseRecordAdd(@RequestBody Purchase purchase){
        Result result = purchaseService.inWarehouseRecordAdd(purchase);
        return result;
    }
}
